//用户管理模块
import { request } from "@/utils/request"
import { SetUserRole, UserData, UserRoleData } from "./type"
enum API{
    //获取用户列表
    USERLIST_URL = '/admin/acl/user/',
    ADDUSER_URL = '/admin/acl/user/save',
    UPDATEUSER_URL= '/admin/acl/user/update',
    //获取用户角色
    USERROLE_URL = '/admin/acl/user/toAssign/',
    //分配角色
    SETROLE_URL  = '/admin/acl/user/doAssignRole',
    //删除某一个账号
    DELETEUSER_URL= '/admin/acl/user/remove/',
    //批量删除的接口
    DELETEALLUSER_URL = '/admin/acl/user/batchRemove',

}
export const reqGetUserList = (page:number,limit:number,username?:string)=>request.get<any,any>(API.USERLIST_URL+`${page}/${limit}/?username=${username}`)
// //新增用户
// export const reqAddUser = (data:UserData)=>request.post<any,any>(API.ADDUSER_URL,data)
// //修改用户
// export const reqUpdateUser = (data:UserData)=>request.put<any,any>(API.UPDATEUSER_URL)

export const reqAddAndUpdataUser = (data:UserData)=>{
    if(data.id){
        return request.put<any,any>(API.UPDATEUSER_URL,data)
    }else{
        return request.post<any,any>(API.ADDUSER_URL,data)
    }
}

export const reqUserRole = (adminId:number)=>request.get<any,UserRoleData>(API.USERROLE_URL+adminId)

//分配用户角色
export const reqSetUserRole = (data:SetUserRole)=>request.post<any,any>(API.SETROLE_URL,data)
//删除某一个账号
export const reqDeleteUser = (id:number)=>request.delete<any,any>(API.DELETEUSER_URL+id)
//批量删除账号
export const reqDeleteAllUser = (idList:number[])=>request.delete<any,any>(API.DELETEALLUSER_URL,{data:idList})